﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Quizzer.Model;

namespace Quizzer.DataAccess
{
    public static class AnswerRepository
    {
        readonly static Dictionary<Guid, Answer> _answers;

        static AnswerRepository()
        {
            _answers = LoadAnswers();
        }

        static Dictionary<Guid, Answer> LoadAnswers()
        {
            return Answer.Items;
        }

        public static Answer GetAnswer(Answer answer)
        {
            if (_answers.Keys.Contains(answer.Id))
                return _answers[answer.Id];
            else
                return null;
        }

        public static ObservableCollection<Answer> GetAnswersOnQuestion(Question question)
        {
            var query = from answer in _answers.Values
                        where answer.QuestionID == question.Id
                        select answer;

            return new ObservableCollection<Answer>(query.ToList());
        }
    }
}
